package com.yh.correct.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.IGradeMapper;
import com.yh.correct.model.Grade;
import com.yh.correct.model.Page;
import com.yh.correct.service.IGradeService;
	/**
	 * 监管等级服务层实现类
	 * @author Administrator
	 *
	 */
@Service
public class GradeSeviceImpl implements IGradeService {
	private static Logger logger = LogManager.getLogger(GradeSeviceImpl.class);
	@Autowired
	private IGradeMapper igraderMapper;

	/**
	 * 
	 *@author Administrator
	 *@注释 : 增加监管等级
     */
	@Override
	public int addGrade(Grade grade) throws Exception {
		// TODO Auto-generated method stub
		logger.debug("增加监管等级! + GradeSeviceImpl");
		return igraderMapper.addGrade(grade);
	}
	/**
	 *@author Administrator
	 *@注释 : 
     *	删除监管等级
     */
	@Override
	public int delGrade(int id) throws Exception {
		// TODO Auto-generated method stub
		logger.debug("删除监管等级! + GradeSeviceImpl");
		return igraderMapper.delGrade(id);
	}
		/**
		 * 批量删除
		 */
	@Override
	public int deleteBatch(List<Integer> list) {
			int i = 0;
			try {
				i = igraderMapper.deleteBatch(list);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return i;
		}
	/**
	 *@author Administrator
	 *@注释 : 
     *	修改监管等级
     */
	@Override
	public int editGrade(Grade grade) throws Exception {
		// TODO Auto-generated method stub
		logger.debug("修改监管等级! + GradeSeviceImpl");
		return igraderMapper.editGrade(grade);
	}
	/**
	 *@author Administrator
	 *@注释 : 
	 *	根据id查询监管等级
	 */
	@Override
	public Map<String,Object> getIdGrade(int id) throws Exception {
		logger.debug("根据id监管等级! + GradeSeviceImpl");
		return igraderMapper.getIdGrade(id);
	}
	/**
	 *@author Administrator
	 *@注释 : 模糊查询监管等级
	 *	
	 */
	@Override
	public Page getLikeGrades(Map<String, Object> grade) throws Exception {
		// TODO Auto-generated method stub
		Page page=new Page();
		page.setTotalNum(igraderMapper.getLikeGradesCount(grade));
		int pageSize=Integer.parseInt(String.valueOf(grade.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum=Integer.parseInt(String.valueOf(grade.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(igraderMapper.getLikeGrades(grade));
		logger.debug("模糊查询监管等级 + GradeSeviceImpl");
		return page;

	}
	/**
	 *@author Administrator
	 *@注释 : 查询所有监管等级
*	
*/
	@Override
	public List<Map<String,Object>> getAllGrade() throws Exception {
		
		return igraderMapper.getAllGrade();
	}
}